package com.faceye.core.repository.jdbc;

import com.faceye.core.repository.jdbc.wrapper.Column;
import com.faceye.core.repository.jdbc.wrapper.Row;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

@Slf4j
public class RowUtil {
    /**
     * 获取指定列的值
     * @param columnName
     * @return
     */
    public static Object getColumnValue(Row row, String columnName){
        Object val=null;
        for(Column column:row.getColumns()){
            if(StringUtils.equalsIgnoreCase(column.getName(),columnName)){
                val = column.getValue();
                break;
            }
        }
        return val;
    }

    /**
     * 为某一列设置值
     * @param row
     * @param columnName
     * @param value
     */
    public static void setColumnValue(Row row,String columnName,Object value){
        for(Column column:row.getColumns()){
            if(StringUtils.equalsIgnoreCase(column.getName(),columnName)){
                column.setValue(value);
                break;
            }
        }
    }
}
